package com.zhongge.test;

import java.util.Comparator;
import java.util.PriorityQueue;

class Student implements Comparable<Student>{
    int age;

    public Student(int age) {
        this.age = age;
    }
    @Override
    public int compareTo(Student o) {
        return o.age - this.age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}

//小根堆==》顺着写
class MinHeap implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o1.compareTo(o2);
    }
}
//大根堆==》逆着写
class MaxHeap1 implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
/**
 * @ClassName queue
 * @Description TODO 测试优先级队列
 * @Author zhongge
 * @Date 2025/10/4 15:32
 * @Version 1.0
 */
public class queue {

    public static void main(String[] args) {
        //大根堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new MaxHeap1());
        priorityQueue.offer(5);
        priorityQueue.offer(12);
        //获取堆顶元素
        System.out.println(priorityQueue.peek());
    }
    public static void main2(String[] args) {
        //小根堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new MinHeap());
        priorityQueue.offer(5);
        priorityQueue.offer(12);
        //获取堆顶元素
        System.out.println(priorityQueue.peek());
    }
    public static void main1(String[] args) {
        PriorityQueue<Student> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(new Student(5));
        priorityQueue.offer(new Student(12));
        //获取堆顶元素
        System.out.println(priorityQueue.peek());
    }
}
